package me.zhengjie.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.app.domain.UserMember;
import me.zhengjie.modules.app.mapper.UserMemberMapper;
import me.zhengjie.modules.app.service.UserMemberService;
import me.zhengjie.modules.security.service.dto.AppJwtUserDto;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

/**
* @author xz
* @date 2025/06/23
*/
@Slf4j
@Service
public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMember> implements UserMemberService {

    /**
     * 新增记录
     * @param dataModel
     * @return
     */
    @Override
    public int insertData(UserMember dataModel){
        Date insertDate=new Date();
        dataModel.setCreateTime(insertDate);
        dataModel.setUpdateTime(insertDate);
        return getBaseMapper().insert(dataModel);
    }

    @Override
    public AppJwtUserDto loadUserByUsername(String userName) {
        LambdaQueryWrapper<UserMember> userMemberWrapper = Wrappers.lambdaQuery();
        userMemberWrapper.eq(UserMember::getUsername, userName);
        UserMember userMember =getBaseMapper().selectOne(userMemberWrapper);
        if (userMember!=null) {
            return new AppJwtUserDto(userMember, new ArrayList<>());
        }
        return null;
    }
}
